<!DOCTYPE html>
<html>
<head>
    <title>FileReader Example</title>

    <script type="text/javascript" charset="utf-8" src="js/cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

        // Wait for device API libraries to load
        //
        document.addEventListener("deviceready", onDeviceReady, false);
        function onLoad() {

        }

        // device APIs are available
        //
        function onDeviceReady() {
            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
        }

        function gotFS(fileSystem) {
            fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
        }

        function gotFileEntry(fileEntry) {
            fileEntry.file(gotFile, fail);
        }

        function gotFile(file){
//            readDataUrl(file);
            readAsText(file);
        }

        function readDataUrl(file) {
            var reader = new FileReader();
            reader.onloadend = function(evt) {
                console.log("Read as data URL");
                console.log(evt.target.result);
            };
//            alert(reader.readAsDataURL(file));
        }

        function readAsText(file) {
            var reader = new FileReader();
            reader.onloadend = function(evt) {
                alert('test222');
//                console.log("Read as text");
                test(evt.target.result);
                console.log(evt.target.result);
            };
            alert(file.name);
            alert(file.fullPath);
            alert(reader.readAsText(file));
        }
        function test(result) {
            alert(result);
        }
        function fail(evt) {
            alert('fail');
            console.log(evt.target.error.code);
        }

    </script>
</head>
<body>
<h1>Example</h1>
<p>Read File2</p>
</body>
</html>
